/**
 *	Monopolymorphism - A Java-based monopoly!
 *
 *	The final project of 
 *	Object-Oriented Programming Design of NTUCSIE
 *
 *	Authors:
 *		ChungKingSing.
 *		Qing-Cheng Li.
 */
package monopolymorphism;

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;

public class MapFactory{
	public static String[] readMaps(){
		int num = 0;
		Scanner fin = null;
		String[] maps;
		try{
			fin = new Scanner(new FileInputStream("map/maps"));
			num = fin.nextInt();
		}catch(FileNotFoundException e){
		
		}
		maps = new String[num];
		for(int i=0;i<num;i++){
			maps[i] = fin.next();
		}
		return maps;
	}
	
	public static ArrayList<Land> buildLand(String mapName){
		Scanner fin = null;
		ArrayList<Land> lands = new ArrayList<Land>();
		mapName = "map/"+mapName+"/";
		String configFile = mapName + "mapconfig";
		System.out.println("Reading "+configFile +"...");
	
		try{
			fin = new Scanner(new FileInputStream(configFile));
		}catch(FileNotFoundException e){
			return null;
		}
	
		Land tmpLand;
		Property tmpProperty;
		int id,b,d,oid,p,hc,l;
		String n,kind;
		int[] ary;
	
		for(int i=0;i<40;i++){
			id = fin.nextInt();
			kind = fin.next();			
			switch(kind.charAt(0)){
				case 'S':
					tmpLand = new SpecialLand(id);
					lands.add(tmpLand);
					break;
				case 'N':
					b = fin.nextInt();
					d = fin.nextInt();
					oid = fin.nextInt();
					n = fin.next();
					p = fin.nextInt();
					hc = fin.nextInt();
					l = fin.nextInt();
					ary = new int[6];
					for(int j=0;j<6;j++)
						ary[j] = fin.nextInt();
					
					tmpProperty = 
						new NormalProperty(b,d,null,n,p,hc,l,ary);
					tmpLand = new NormalLand(id,tmpProperty);
					lands.add(tmpLand);
					break;
				case 'C':
					Card card;
					if(fin.nextInt()==0){
						card = new ChanceCard();
					}else{
						card = new DestinyCard();
					}
					tmpLand = new CardLand(id,card);
					lands.add(tmpLand);
					break;
				case 'M':
					tmpLand = new MoneyLand(id,fin.nextInt());
					lands.add(tmpLand);
					break;
				case 'A':
					b = fin.nextInt();
					d = fin.nextInt();
					oid = fin.nextInt();
					n = fin.next();
					p = fin.nextInt();
					ary = new int[4];
					for(int j=0;j<4;j++)
						ary[j] = fin.nextInt();
					tmpProperty = 
						new AirportProperty(b,d,null,n,p,ary);
					tmpLand = new NormalLand(id,tmpProperty);
					lands.add(tmpLand);
					break;
				default:
					break;
			}
		}
		
		return lands;
	}
}
